package android.medicalcloud.com.yiapp.yilian.ui.fragment;

import android.medicalcloud.com.yiapp.R;
import android.medicalcloud.com.yiapp.base.fragment.BaseFragment;
import android.medicalcloud.com.yiapp.base.net.lisener.ViewNetCallBack;
import android.medicalcloud.com.yiapp.yilian.model.BannerModel;
import android.medicalcloud.com.yiapp.yilian.ui.view.AutoScrollViewPager;
import android.medicalcloud.com.yiapp.yilian.ui.view.MainPageIndicator;
import android.medicalcloud.com.yiapp.yilian.ui.view.adapter.BannerAdapter;
import android.medicalcloud.com.yiapp.yilian.utils.android.IntentTool;
import android.view.View;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanggenlin on 17-5-18.
 */
public class HomeFragment extends BaseFragment implements
        ViewNetCallBack, BannerAdapter.ClickListener, View.OnClickListener {
    AutoScrollViewPager mainViewPager;
    MainPageIndicator indicator;
    public final static int BANNER_AUTO_SCROLL_INTERVAL = 3000;
    BannerAdapter bannerAdapter;
    @Override
    protected void initView(View view) {
        mainViewPager = (AutoScrollViewPager)view.findViewById(R.id.mainViewPager);
        indicator = (MainPageIndicator)view.findViewById(R.id.indicator);
        view.findViewById(R.id.main_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentTool.webview(getActivity(),"https://www.baidu.com/","签约医院与医生");
            }
        });
        view.findViewById(R.id.main_right).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentTool.webview(getActivity(),"https://www.baidu.com/","了解医联");
            }
        });


    }

    private void initPager() {
        bannerAdapter = new BannerAdapter(getActivity());
        bannerAdapter.setListener(this);
        mainViewPager.setAdapter(bannerAdapter);
        mainViewPager.setAutoScrollDurationFactor(3.0f);
        mainViewPager.setInterval(BANNER_AUTO_SCROLL_INTERVAL);
        mainViewPager.startAutoScroll();
        indicator.setViewPager(mainViewPager);
        banners = new ArrayList<>();

        BannerModel m1=new BannerModel();
        banners.add(m1);
        banners.add(m1);
        banners.add(m1);
        banners.add(m1);
        bannerAdapter.setRes(banners);
        indicator.setSize(banners.size());

    }
    List<BannerModel> banners;


    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {
        initPager();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fra_home;
    }

    public static HomeFragment newInstance() {
        HomeFragment homeFragment = new HomeFragment();
        return homeFragment;
    }

    @Override
    public void click(View view, int positon) {
        IntentTool.webview(getActivity(),"https://www.baidu.com/","test");
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onConnectStart(Object o) {

    }

    @Override
    public void onConnectEnd() {

    }

    @Override
    public void onFail(Exception e, Object o, String reslut) {

    }

    @Override
    public void onData(Serializable result, int flag, boolean fromNet, Object o) {

    }
}
